package com.tcr.action;

import java.util.List;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import com.tcr.common.TcProject;
import com.tcr.dao.ProjectDao;

public class ProjMgtAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public String getP_name() {
		return p_name;
	}

	public void setP_name(String pName) {
		p_name = pName;
	}

	public String getP_svn() {
		return p_svn;
	}

	public void setP_svn(String pSvn) {
		p_svn = pSvn;
	}

	public String getP_code() {
		return p_code;
	}

	public void setP_code(String pCode) {
		p_code = pCode;
	}

	public String getPid() {
		return pid;
	}

	public void setPid(String pid) {
		this.pid = pid;
	}

	private String p_name;
	private String p_svn;
	private String p_code;
	private String pid;
	private List<TcProject> projs;

	public String addproj() {
		String p_name = this.getP_name().trim();
		String p_svn = this.getP_svn().trim();
		int p_code = Integer.parseInt(this.getP_code().trim());

		boolean b = false;
		b = ProjectDao.addProj(p_name, p_code, p_svn);
		if (b) {
			return Action.SUCCESS;
		} else {
			super.addFieldError("error", "创建项目失败");
			return "input";
		}
	}

	public String projmgt() {
		List<TcProject> tc_projects = ProjectDao.getAllPrjs();
		this.setProjs(tc_projects);
		return Action.SUCCESS;
	}

	public String delproj() {
		int pid = Integer.parseInt(this.getPid().trim());
		ProjectDao.delProj(pid);
		return Action.SUCCESS;
	}

	public void setProjs(List<TcProject> projs) {
		this.projs = projs;
	}

	public List<TcProject> getProjs() {
		return projs;
	}

}
